class State:
    LOOK_FOR_STRING = "look_for_string"
    IN_STRING = "in_string"
    COPY_NEXT_CHAR = "copy_next_char"


class Event:
    DOUBLE_QUOTATION = "double_quotation"
    BACK_SLASH = "back_slash"
    OTHER_CHAR = "other_char"

    @staticmethod
    def of(char):
        if char == '"':
            return Event.DOUBLE_QUOTATION
        elif char == '\\':
            return Event.BACK_SLASH
        else:
            return Event.OTHER_CHAR


class Action:
    IGNORE = "ignore"
    START_NEW_STRING = "start_new_string"
    ADD_CURRENT_TO_STRING = "add_current_to_string"
    FINISH_CURRENT_STRING = "finish_current_string"


class Pair:
    def __init__(self, state, action):
        self.state = state
        self.action = action


class StringExtractor:

    def __init__(self):
        self.current_state = State.LOOK_FOR_STRING
        self.result = []
        self.current_string = []

        # 状态转换表
        self.transitions = {
            (State.LOOK_FOR_STRING, Event.DOUBLE_QUOTATION): Pair(State.IN_STRING, Action.START_NEW_STRING),
            (State.LOOK_FOR_STRING, Event.OTHER_CHAR): Pair(State.LOOK_FOR_STRING, Action.IGNORE),
            (State.IN_STRING, Event.DOUBLE_QUOTATION): Pair(State.LOOK_FOR_STRING, Action.FINISH_CURRENT_STRING),
            (State.IN_STRING, Event.BACK_SLASH): Pair(State.COPY_NEXT_CHAR, Action.IGNORE),
            (State.IN_STRING, Event.OTHER_CHAR): Pair(State.IN_STRING, Action.ADD_CURRENT_TO_STRING),
            (State.COPY_NEXT_CHAR, Event.OTHER_CHAR): Pair(State.IN_STRING, Action.ADD_CURRENT_TO_STRING)
        }

    def trigger(self, ch):
        event = Event.of(ch)
        pair = self.transitions.get((self.current_state, event), self.transitions.get((self.current_state, Event.OTHER_CHAR)))
        self.current_state = pair.state
        self.do_action(pair.action, ch)

    def do_action(self, action, current_char):
        if action == Action.IGNORE:
            return
        elif action == Action.START_NEW_STRING:
            self.current_string = []
        elif action == Action.ADD_CURRENT_TO_STRING:
            self.current_string.append(current_char)
        elif action == Action.FINISH_CURRENT_STRING:
            self.result.append(''.join(self.current_string))

    def get_result(self):
        return ' '.join(self.result)


if __name__ == "__main__":
    # 示例源代码
    source = '老师说，"一般学习程序设计的第一个程序就是\\"Hello,World!\\""'

    extractor = StringExtractor()

    for ch in source:
        extractor.trigger(ch)

    result = extractor.get_result()
    print(result)

